package com.stlm2.controller;

import com.stlm2.dems.service.DdmShopService;
import com.stlm2.dems.service.ShopAdminUserService;
import com.stlm2.util.codecontent.CodeContent;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * Created by zlq on 2017/10/18.
 */
@Controller
@RequestMapping("/shopAdminUser")
public class ShopAdminUserController {
    @Resource
    private ShopAdminUserService shopAdminUserService;
    /*zlq
* crm查询店铺人员列表页面
* */
    @RequestMapping(value="/listView",produces="application/json;charset=UTF-8")
    public ModelAndView listView(ModelAndView modelAndView){
        modelAndView.setViewName("/shopAdminUser/list");
        return modelAndView;
    }

    /*
*获取店铺成员列表
* zlq
* token；
* page：页码
* shopId:店铺ID
* userStateValue:用户状态值
 */
    @ResponseBody
    @RequestMapping(value="/getShopUserList.json",produces="application/json;charset=UTF-8")
    public  String  getShopUserList(ModelMap model, String token,String page,String shopId,String userStateValue){
        String data=null;
        try {
            data=shopAdminUserService.getShopUserList(model,token,page,shopId, userStateValue);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"查询失败",data);
        }
        return  data;
    }
    /*
    *zlq
    * crm获取我的店铺下拉框信息
    * token:
     */
    @ResponseBody
    @RequestMapping(value="/getMyShopList.json",produces="application/json;charset=UTF-8")
    public  String  getMyShopList(ModelMap model,String token){
        String data=null;
        try {
            data=shopAdminUserService.getMyShopList(model,token);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"查询失败",data);
        }
        return  data;
    }


	/*
	*创建后台店铺用户
	* zlq
	* @param  token
	* @param  userAccount：新用户账号
	* @param  realName：新用户名字
	* @param  roleId：新用户角色ID
	* @param  phone:手机号
	* @param  shopId:店铺ID
	 */
    @ResponseBody
    @RequestMapping(value="/addShopUser.json",produces="application/json;charset=UTF-8")
    public  String addShopUser(ModelMap model ,String token,String shopId,String userAccount,String realName,String roleId,String phone,String companyCode){
        String data=null;
        try {
            data=shopAdminUserService.addShopUser( model,token,shopId, userAccount,realName,roleId,phone,companyCode);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"添加失败",data);
        }
        return  data;
    }

    @ResponseBody
    @RequestMapping(value="/addShopMember.json",produces="application/json;charset=UTF-8")
    public  String  addShopMember(ModelMap model ,String token ,String shopId,String userId){
        String data=null;
        try {
            data=shopAdminUserService.addShopMember( model,token,shopId,userId);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"添加失败",data);
        }
        return  data;
    }
}
